﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MapEditor.Windows.Ressources
{
    public partial class RessourcesSelection : Form
    {
        public string Selection{ get; set; }

        private string path;

        public RessourcesSelection(string path)
        {
            InitializeComponent();

            this.path = path;

            this.listBoxRessources.Items.Clear();
            foreach (var file in Directory.GetFiles(this.path, "*.png"))
            {
                this.listBoxRessources.Items.Add(Path.GetFileNameWithoutExtension(file));
            }
        }

        private void buttonAnnuler_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void listBoxRessources_SelectedIndexChanged(object sender, EventArgs e)
        {
            var fileName = this.listBoxRessources.SelectedItem.ToString();
            pictureBox1.Image = Image.FromFile(this.path + "\\" + fileName + ".png");
        }

        private void buttonValider_Click(object sender, EventArgs e)
        {
            this.Selection = this.listBoxRessources.SelectedItem.ToString();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void listBoxRessources_DoubleClick(object sender, EventArgs e)
        {
            if (this.listBoxRessources.SelectedItem != null)
            {
                this.Selection = this.listBoxRessources.SelectedItem.ToString();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
